public class Text3 {
    //202.快乐数
    //判断有环算法原理：快慢双指针    双指针只是种思想，记得摆脱链表
    public int AddSquare(int n){
        int sum = 0;
        while(n != 0){
            int v = n % 10;
            sum += v *v;
            n /= 10;
        }

        return sum;
    }

    public boolean isHappy(int n) {
        int cur = n;
        int dest = AddSquare(n);

        while(dest != cur){
            //铁定会相遇，判断相遇时是否会是1即可（鸽巢原理）
            dest = AddSquare(AddSquare(dest));
            cur = AddSquare(cur);
        }
        return dest == 1 ;
    }
}
